package org.kl.bf.utils;

import java.util.Calendar;
import java.util.Date;

import org.joda.time.DateTime;

/**
 * @Author hqm
 * @CreateTime 2015年3月10日 上午9:36:08
 */
public class KLDateTimeUtils {

	public static final String[] WEEKS = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
	public static final String[] CHINESE_NUMBER = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };

	/**
	 * 本月第一天
	 * 
	 * @return
	 */
	public static DateTime currentMonth1st() {
		return new DateTime().dayOfMonth().withMinimumValue().withTimeAtStartOfDay();
	}

	/**
	 * 本月第一天
	 * 
	 * @return
	 */
	public static String currentMonth1st_yyyyMMddHHmmss() {
		return currentMonth1st().toString("yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 本月第一天
	 * 
	 * @return
	 */
	public static String currentMonth1st_yyyyMMdd() {
		return currentMonth1st().toString("yyyy-MM-dd");
	}

	/**
	 * 本月月末
	 * 
	 * @return
	 */
	public static DateTime currentMonthEnd() {
		return new DateTime().dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue();
	}

	/**
	 * 本月月末
	 * 
	 * @return
	 */
	public static String currentMonthEnd_yyyyMMddHHmmss() {
		return currentMonthEnd().toString("yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 本月月末
	 * 
	 * @return
	 */
	public static String currentMonthEnd_yyyyMMdd() {
		return currentMonthEnd().toString("yyyy-MM-dd");
	}

	/**
	 * 根据日期取得星期几
	 * 
	 * @param date
	 * @return
	 */
	public static String getWeek(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (week_index < 0) {
			week_index = 0;
		}
		return WEEKS[week_index];
	}

	/**
	 * 取得日期是某年的第几周
	 * 
	 * @param date
	 * @return
	 */
	public static int getWeekOfYear(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int week_of_year = cal.get(Calendar.WEEK_OF_YEAR);
		return week_of_year;
	}

	/**
	 * 取得某个月有多少天
	 * 
	 * @param year
	 * @param month
	 * @return
	 */
	public static int getDaysOfMonth(int year, int month) {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month - 1);
		int days_of_month = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		return days_of_month;
	}
}
